package com.itheima.text2;

import java.io.IOException;
import java.net.*;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static java.time.format.DateTimeFormatter.*;


public class UDPSend {
    public static void main(String[] args) throws IOException, InterruptedException {
        DatagramSocket socket = new DatagramSocket();



        while (true) {
            Thread t = new Thread();
            Thread.sleep(1000);
            t.start();
            //获取当前时间
            LocalDateTime date = LocalDateTime.now();
            //初始化格式
            DateTimeFormatter dtf = ofPattern("yyyy-MM-dd HH:mm:ss");

         //   dtf.format(date);
            String s = new String(dtf.format(date));
            byte[] bytes = s.getBytes();

            DatagramPacket packet = new DatagramPacket(bytes, bytes.length,
                    InetAddress.getByName("192.168.23.64"), 10002
            );
            Thread.sleep(1000);
            socket.send(packet);
        }
    }
}

